// pages/brochure/index/index.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 组件参数设置，传递到组件
    defaultData: {
      title: "", // 导航栏标题
      showHome: false, //是否显示回到首页按钮
      showBack: false, //是否显示返回按钮
      showLogo: false, //是否显示logo
      bgColor: 'transparent',
      isShare: 0
    },
    requestUrl: app.baseUrl,
    shareTitle: '',
    shareImg: '',
    baseUrl: app.baseUrl,
    videoUrl: app.videoUrl,
    version: app.globalData.version,
    currentTab1: 0, //预设当前项的值
    currentTab2: 0, //预设当前项的值
    lmArr: [{
      id: 0,
      path1: app.videoUrl + 'ML03.mp4?v=' + app.version, //'http://qn.andwind.cc/small/ML03.mp4?v='+app.version,
      path2: app.baseUrl + 'images/brochure/lmIcon1.png',
      url: ''
    }, {
      id: 1,
      path1: app.videoUrl + 'ML01.mp4?v=' + app.version, //'http://qn.andwind.cc/small/ML01.mp4?v='+app.version,
      path2: app.baseUrl + 'images/brochure/lmIcon2.png',
      url: ''
    }, {
      id: 2,
      path1: app.videoUrl + 'ML02.mp4?v=' + app.version, //'http://qn.andwind.cc/small/ML02.mp4?v='+app.version,
      path2: app.baseUrl + 'images/brochure/lmIcon3.png',
      url: ''
    }, {
      id: 3,
      path1: app.videoUrl + 'ML04.mp4?v=' + app.version, //'http://qn.andwind.cc/small/ML04.mp4?v='+app.version,
      path2: app.baseUrl + 'images/brochure/lmIcon4.png',
      url: ''
    }],
    xmArr: [
      {
        id: 1,
        path: app.baseUrl + 'images/brochure/ztIcon1.png',
  
      },{
      id: 2,
      path: app.baseUrl + 'images/brochure/ztIcon3.png',
    },{
      id: 0,
      path: app.baseUrl + 'images/brochure/ztIcon2.png',
    },{
      id: 3,
      path: app.baseUrl + 'images/brochure/ztIcon4.png',
    }],
    openid:''
  },
  // 滚动切换标签样式
  switchTab1: function (e) {

    this.setData({
      currentTab1: e.detail.current,
    });
  },
  goLYBD() {
    wx.navigateTo({
      url: '/pages/brochure/menu/index',
    })
  },
  goDetail(e) {
    console.log(e)
    var itemId = e.currentTarget.dataset.itemId;
    if (itemId == 0) {
      wx.navigateTo({
        url: '/pages/brochure/byxItem/whpp?videoname=whpp',
      })
    } else if (itemId == 1) {
      wx.navigateTo({
        url: '/pages/brochure/byxItem/whpp?videoname=ssdc',
      })
    } else if (itemId == 2) {
      wx.navigateTo({
        url: '/pages/brochure/byxItem/value',
      })
    } else if (itemId == 3) {
      wx.navigateTo({
        url: '/pages/brochure/album/index',
      })
    }
  },
  goItem(e) {

    var itemId = e.currentTarget.dataset.itemid;
    if (itemId == 0) {
      wx.navigateTo({
        url: '/pages/brochure/lxbdItem/menu',
      })

    } else if (itemId == 1) {
      wx.navigateTo({
        url: '/pages/brochure/menu/index',
      })

    } else if (itemId == 2) {
      wx.navigateTo({
        url: '/pages/brochure/yjItem/menu',
      })
    } else if (itemId == 3) {
      wx.navigateTo({
        url: '/pages/commingsoon/index',
      })
    }
  },
  //获取微信分享信息
  getShareInfo(openid) {
    var that = this;
    wx.request({
      url: that.data.requestUrl + 'getLsShareInfo.php',
      method: 'POST',
      data: {
        type:2,
        openid: openid,
        pid:1,
        id:40
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        that.setData({
          shareTitle: res.data.shareTitle,
          shareImg: res.data.shareImg
        });
      },
      fail: function (res) {}
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var that=this;
    var is_share = options.is_share;
    //判断返回的跳转路径
    if (is_share == 1) {
      this.setData({
        ['defaultData.isShare']: 1
      });
    }


      //获取缓存中的openid
      var openid = wx.getStorageSync('openid');

      if (openid == '') {
        //缓存中没有openid
        //获取所需页面信息
        wx.login({
          success: function (res) {
            if (res.code) {
              //发起网络请求
              wx.request({
                url: that.data.requestUrl + 'getOpenid.php',
                method: 'POST',
                data: {
                  'code': res.code
                },
                header: {
                  'content-type': 'application/x-www-form-urlencoded'
                },
                success: function (res) {
                  //缓存微信openid
                  wx.setStorageSync('openid', res.data.openid);
                  that.setData({
                    openid: res.data.openid
                  });
  
                  //调用分享
                  that.getShareInfo(res.data.openid);
                },
                fail: function (res) {}
              });
            }
          }
        });
      } else {
        that.setData({
          openid: openid
        });
  
        //调用分享
        that.getShareInfo(openid);
      }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    if (typeof this.getTabBar === 'function' && this.getTabBar()) {
      this.getTabBar().setData({
        selected: 1,
      })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    var that = this;
    return {
      title: that.data.shareTitle,
      path: '/pages/brochure/index?is_share=1',
      imageUrl: that.data.shareImg,
      success: function (res) {

      },
      fail: function (res) {

      }
    }
  },
  // 分享朋友圈
  onShareTimeline() {
    var that = this;
    return {
      title: that.data.shareTitle,
      query: 'is_share=1',
      imageUrl: that.data.shareImg,
      success: function (res) {

      },
      fail: function (res) {

      }
    }
  }
})